﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ERMap;

namespace PhoneBook.Manage
{
    public class SysRole
    {
        public static DataSet getGroupRole(string groupid)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(" select * from sysrole where groupid = @groupid and isnull(isdel,0) = 0");

            Hashtable param = new Hashtable();
            param["groupid"] = groupid;

            return ERMapHelper.getCustomData(sb.ToString(), param);
        }

        public static Hashtable get(string roleid)
        {
            Hashtable keys = new Hashtable();
            keys.Add("roleid", roleid);
            return ERMapHelper.getmodel("sysrole", keys);
        }

        public static DataSet getlist()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(" select * from sysrole where isnull(isdel,0) = 0 ");

            return ERMapHelper.getCustomData(sb.ToString(), null);
        }

        public static DataSet getManagerRole()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(" select * from sysrole where isnull(groupid,'') = '' and isnull(isdel,0) = 0 ");

            return ERMapHelper.getCustomData(sb.ToString(), null);
        }

        public static Hashtable getWebUserRole()
        {
            Hashtable keys = new Hashtable();
            keys.Add("rolename", "个人用户");
            return ERMapHelper.getmodel("sysrole", keys);
        }

        public static void del(string roleid)
        {
            Hashtable keys = new Hashtable();
            keys["roleid"] = roleid;
            ERMap.ERMapHelper.delmodel("sysrole", keys);
        }

        public static void add(Hashtable sysrole)
        {
            string roleid = Commons.StringUtil.GetID_15();
            sysrole["roleid"] = roleid;

            ERMapHelper.setmodel("sysrole", "roleid", sysrole);
        }

        public static void edit(Hashtable sysrole)
        {
            ERMapHelper.setmodel("sysrole", "roleid", sysrole);
        }
    }
}
